
package com.hulk.ratel.persistence.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class CommonMetaObjectHandler implements MetaObjectHandler {

    /**
     * 乐观锁版本号
     */
    private final String reversion = "reversion";
    /**
     * 创建时间
     */
    private final String createdTime = "createdTime";
    /**
     * 修改时间
     */
    private final String updatedTime = "updatedTime";
    /**
     * 创建者ID
     */
    private final String createBy = "createBy";

    /**
     * 修改者ID
     */
    private final String updateBy = "updateBy";




    @Override
    public void insertFill(MetaObject metaObject) {
        setInsertFieldValByName(createdTime, LocalDateTime.now(), metaObject);
        //setInsertFieldValByName(createUid, currentUid(), metaObject);
        setInsertFieldValByName(updatedTime, LocalDateTime.now(), metaObject);
        setInsertFieldValByName(reversion, 0, metaObject);
        //setInsertFieldValByName(updateUid, currentUid(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setUpdateFieldValByName(updatedTime, LocalDateTime.now(), metaObject);
        //setUpdateFieldValByName(updateUid, currentUid(), metaObject);
    }

    /**
     * 获取当前用户ID
     */
//    private Integer currentUid() {
//        Integer uid = null;
//        try {
//            uid = ApiUtils.currentUid();
//        } catch (Exception ignored) {
//        }
//        return uid;
//    }

}

